package com.matt.controller.web;

import com.matt.domain.Classes;
import com.matt.domain.course.CoursePlanClasses;
import com.matt.foundation.DO.course.WebCoursePageDO;
import com.matt.foundation.constant.ClassesConstant;
import com.matt.foundation.constant.RequestConstant;

import com.matt.commons.model.StatusResponse;
import com.matt.foundation.query.CourseQuery;
import com.matt.foundation.vo.course.CoursePlanEarlyListVo;
import com.matt.service.*;

import com.matt.service.remoteCall.SsoCallService;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/4
 * *******************************
 */
@RestController
@RequestMapping("/web/course_early")
public class WebCourseEarlyController {

    @Autowired
    private CourseEarlyService courseEarlyService;
    @Autowired
    private CourseService courseService;


    @Autowired
    private CoursePlanClassesService coursePlanClassesService;

    @Autowired
    private SsoCallService ssoCallService;

    @Autowired
    private ClassesService classesService;

    @ApiOperation(value = "获取排好的课程",httpMethod = "POST")
    @RequestMapping("/plan_by_date")
    public StatusResponse planByDate(@RequestHeader(RequestConstant.TICKET) String ticket, String areaId, String beginDate, String endDate) {
     /*   StaffRoleDTO staffRoleDTO = ssoCallService.getRoleByPlatform(ticket, TEACH_PLATFORM_TYPE);*/
       /* if (!(PermissionConstant.Role.GARDEN_LEADER.codeOf().equals(staffRoleDTO.getRoleCode()) || PermissionConstant.Role.ADMIN.codeOf().equals(staffRoleDTO.getRoleCode())))
            throw new BusinessException(ErrorCode.PROMISSION_DELINED, "你权限不够，无法查看");*/
        List<CoursePlanEarlyListVo> coursePlans = courseEarlyService.getPlanByAreaBetweenDays(beginDate, endDate, areaId);
        return StatusResponse.success(coursePlans);
    }

//    @RequestMapping("/plan_detail")
//    public StatusResponse planDetail(@RequestHeader(RequestConstant.TICKET) String ticket, String planId) {
//        CoursePlanDetailVo vo = courseEarlyService.getPlanDetail(planId);
//        return StatusResponse.success(vo);
//    }
//
//    @RequestMapping("/pre_info")
//    public StatusResponse preInfo(@RequestHeader(RequestConstant.TICKET) String ticket) {
//        String areaId =ssoCallService.getStaff(ticket).getAreaId();
//        List<StaffAreaDTO> teacherList = teacherService.getTeacherAndGardenLeaderByArea(areaId);
//        List<Map> typeEarlyList = courseService.findOfficialOldAllType();
//        List<TeachingAreaPageVo> teachingAreaList = teachingAreaService.getTeachingAreaByArea(areaId);
//        Map response = new HashMap();
//        response.put("teacherList", teacherList);
//        response.put("typeEarlyList", typeEarlyList);
//        response.put("teachingAreaList", teachingAreaList);
//        return StatusResponse.success(response);
//    }

    //早教班级列表
    @ApiOperation(value = "早教班级列表",httpMethod = "POST")
    @RequestMapping("/early_classes_list")
    public StatusResponse earlyClassesList(String areaId) {
        List<Classes> classesList = classesService.getClassesByAreaAndCategroy(areaId, ClassesConstant.Category.EARLY.codeOf());
        return StatusResponse.success(classesList);
    }

    @ApiOperation(value = "早教宝宝列表",httpMethod = "POST")
    @RequestMapping("/children_list")
    public StatusResponse childrenList(String coursePlanClassesId) {
        Map map = courseEarlyService.childrenList(coursePlanClassesId);
        return StatusResponse.success(map);
    }

    @ApiOperation(value = "创建早教排课",httpMethod = "POST")
    @RequestMapping("/create_plan")
    public StatusResponse plan(String areaId, String date, String beginTime, String endTime, String classesId, String courseId) {
        CoursePlanClasses planClasses = coursePlanClassesService.createEarly(date, beginTime, endTime, classesId, courseId, areaId);
        return StatusResponse.success(planClasses);
    }

    @ApiOperation(value = "给早教课排宝宝",httpMethod = "POST")
    @RequestMapping("/plan_children")
    public StatusResponse planChildren(String coursePlanClassesId, String[] childrenIds) {
        List<String> childrenIdList = Arrays.asList(childrenIds);
        Boolean result = courseEarlyService.planChildren(coursePlanClassesId, childrenIdList);
        return StatusResponse.success(result);
    }

    @ApiOperation(value = "课程筛选",httpMethod = "POST")
    @RequestMapping("/course_page_by_type")
    public StatusResponse coursePage(@RequestHeader(RequestConstant.TICKET) String ticket, CourseQuery query, Integer courseType,Integer packageType) {
        Page<WebCoursePageDO> page = courseService.getCourseByType(query, courseType,packageType);

        return StatusResponse.success(page);
    }

    @ApiOperation(value = "删除早教课程",httpMethod = "POST")
    @RequestMapping("/deleted")
    public StatusResponse delete(String coursePlanClassesId) {
        Boolean result = courseEarlyService.delete(coursePlanClassesId);
        return StatusResponse.success(result);
    }

    @ApiOperation(value = "提交上周课程",httpMethod = "POST")
    @RequestMapping("/submit_pre_week_plans")
    public StatusResponse goRepeatPage(String areaId, String date) {
        List<CoursePlanClasses> list = courseEarlyService.submitPreWeekPlans(date, areaId);
        return StatusResponse.success(list);
    }
}
